import Constant from "./constant";
export default class HawkEyeMap {
  constructor(viewer) {
    this._viewer = viewer;
    this._hawkEyeMap = null;
  }

  _init() {
    this._hawkEyeMap = new Cesium.Viewer('hawkEyeMap', {
      geocoder: false,
      homeButton: false,
      sceneModePicker: false,
      baseLayerPicker: false,
      navigationHelpButton: false,
      animation: false,
      timeline: false,
      fullscreenButton: false,
    });
    this._hawkEyeMap.cesiumWidget.creditContainer.style.display = 'none';
    this._hawkEyeMap.scene.backgroundColor = Cesium.Color.TRANSPARENT;
    this._hawkEyeMap.imageryLayers.removeAll();

    // 鹰眼图中添加高德路网中文注记图
    this._hawkEyeMap.imageryLayers.addImageryProvider(
      Constant.BASELAYER.GAODE1()
    );
    // 引起事件监听的相机变化幅度
    this._viewer.camera.percentageChanged = 0.01;
    this._bindEvent();
  }

  _bindEvent() {
    // 监听主图相机变化
    this._viewer.scene.preRender.addEventListener(this._syncEyeMap, this);
  }

  // 同步主图与鹰眼地图
  _syncEyeMap() {
    // 监听主图
    new Cesium.ScreenSpaceEventHandler(this._viewer.canvas).setInputAction(() => {
      this._isMainMapTrigger = true;
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    // 判断是否为主图移动
    if (!this._isMainMapTrigger) {
      return false;
    }

    this._hawkEyeMap.camera.flyTo({
      destination: this._viewer.camera.position,
      orientation: {
        heading: this._viewer.camera.heading,
        pitch: this._viewer.camera.pitch,
        roll: this._viewer.camera.roll,
      },
      duration: 0.0,
    })
  }
}